<?php

namespace app\shop\controller;

use think\Request;
use think\Exception;
use think\Db;
use app\shop\model\ClientCategory as ClientCategoryModel;

class ClientCategory extends \ShopController{

    //分类列表
    public function categoryList(Request $request){
        $categoryModel = new ClientCategoryModel();
        try {
            $params = $request->get();
            $data = $categoryModel->categoryList($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //添加分类
    public function add(Request $request){
        $categoryModel = new ClientCategoryModel();
        try {
            $params = $request->post();
            $data = $categoryModel->add($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //分类重命名
    public function rename(Request $request){
        $categoryModel = new ClientCategoryModel();
        try {
            $params = $request->post();
            $data = $categoryModel->rename($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //删除分类
    public function delete($id){
        $categoryModel = new ClientCategoryModel();
        try {
            $data = $categoryModel->delete($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

}